package kosta.service;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import kosta.model.dao.AdminDAO;
import kosta.model.dao.MemberDAO;
import kosta.model.vo.AdminVO;
import kosta.model.vo.ListVO;
import kosta.model.vo.MemberVO;
import kosta.model.vo.MessageVO;
import kosta.model.vo.PagingBean;
import kosta.model.vo.SearchVO;

import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements AdminService{
	@Resource(name="adminDAOImpl")
	private AdminDAO adminDAO;
	@Resource(name = "memberDAOImpl")
	private MemberDAO memberDAO;

	@Override
	public AdminVO adminLogin(AdminVO vo) {
		// TODO Auto-generated method stub
		return adminDAO.adminLogin(vo);
	}
	
	@Override
	public ListVO getMemberList(SearchVO svo) {
		System.out.println("getMemberList 실행");
		String flag = svo.getFlag();
		if(flag==null||flag==""){
			svo.setFlag("memberNo");
		
		}
		
		List<MemberVO> list=adminDAO.getMemberList(svo);
		
		System.out.println("Service getMemberList ="+list);
		int total=adminDAO.totalMemberContent(svo);
		System.out.println("Service totalMemberContent:"+total);
		PagingBean paging=new PagingBean(total,svo.getPageNo(),svo.getKeyword(),svo.getFlag());
		System.out.println(paging);
		ListVO lvo=new ListVO(list,paging);
		System.out.println("Service MemberListVO:"+lvo);
		System.out.println("getMemberList 실행 끝");
		return lvo;
		
	}


	@Override
	public void updateMemberGrade(MemberVO mvo) {
		adminDAO.updateMemberGrade(mvo);
	}

	@Override
	public void adminMemberOut(MemberVO mvo) {
		memberDAO.memberLeave(mvo);
		adminDAO.dropOutMember(mvo);
	}
	
	public void adminDelete(HashMap map, MessageVO msvo){
		adminDAO.adminDeleteFromBid(map);
		adminDAO.adminSendDeleteMessage(msvo);		
		adminDAO.adminDeleteFromDeleteConfirm(map);
		adminDAO.adminDeleteFromAuctionRegister(map);		
		
	}

	@Override
	public ListVO deleteRequestCheckList(SearchVO svo) {
		List list = adminDAO.deleteRequestCheckList();
		int total=adminDAO.deleteRequestCheckListCount();
		System.out.println("Service totalMemberContent:"+total);
		PagingBean paging=new PagingBean(total,svo.getPageNo());
		System.out.println(paging);
		ListVO lvo=new ListVO(list,paging);
		System.out.println("삭제요청된 게시물들:"+lvo);
		return lvo;
	}

	@Override
	public int adminIdDuplCheck(String id) {
		return adminDAO.adminIdDuplCheck(id);
	}
	@Override
	public void downGrade(String memberId){
		adminDAO.downGrade(memberId);
	}
	@Override
	public void refuseAdminDelete(HashMap map, MessageVO msvo){
		adminDAO.adminSendDeleteMessage(msvo);		
		adminDAO.adminDeleteFromDeleteConfirm(map);	
		adminDAO.refuseAdminDelete(map);
		
	}
}
